home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / http_log.h.z / http_log.h
C/C++ Source or Header  |  2002-07-08  |  13KB  |  323 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * Portions of this software are based upon public domain software
  55.  * originally written at the National Center for Supercomputing Applications,
  56.  * University of Illinois, Urbana-Champaign.
  57.  */
  58.  
  59. #ifndef APACHE_HTTP_LOG_H
  60. #define APACHE_HTTP_LOG_H
  61.  
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65.  
  66. #include "apr_thread_proc.h"
  67.  
  68. /**
  69.  * @package Apache logging library
  70.  */
  71.  
  72. #ifdef HAVE_SYSLOG
  73. #include <syslog.h>
  74.  
  75. #ifndef LOG_PRIMASK
  76. #define LOG_PRIMASK 7
  77. #endif
  78.  
  79. #define APLOG_EMERG     LOG_EMERG     /* system is unusable */
  80. #define APLOG_ALERT     LOG_ALERT     /* action must be taken immediately */
  81. #define APLOG_CRIT      LOG_CRIT      /* critical conditions */
  82. #define APLOG_ERR       LOG_ERR       /* error conditions */
  83. #define APLOG_WARNING   LOG_WARNING   /* warning conditions */
  84. #define APLOG_NOTICE    LOG_NOTICE    /* normal but significant condition */
  85. #define APLOG_INFO      LOG_INFO      /* informational */
  86. #define APLOG_DEBUG     LOG_DEBUG     /* debug-level messages */
  87.  
  88. #define APLOG_LEVELMASK LOG_PRIMASK   /* mask off the level value */
  89.  
  90. #else
  91.  
  92. #define    APLOG_EMERG    0    /* system is unusable */
  93. #define    APLOG_ALERT    1    /* action must be taken immediately */
  94. #define    APLOG_CRIT    2    /* critical conditions */
  95. #define    APLOG_ERR    3    /* error conditions */
  96. #define    APLOG_WARNING    4    /* warning conditions */
  97. #define    APLOG_NOTICE    5    /* normal but significant condition */
  98. #define    APLOG_INFO    6    /* informational */
  99. #define    APLOG_DEBUG    7    /* debug-level messages */
  100.  
  101. #define    APLOG_LEVELMASK    7    /* mask off the level value */
  102.  
  103. #endif
  104.  
  105. /* APLOG_NOERRNO is ignored and should not be used.  It will be
  106.  * removed in a future release of Apache.
  107.  */
  108. #define APLOG_NOERRNO        (APLOG_LEVELMASK + 1)
  109.  
  110. /* Use APLOG_TOCLIENT on ap_log_rerror() to give content
  111.  * handlers the option of including the error text in the 
  112.  * ErrorDocument sent back to the client. Setting APLOG_TOCLIENT
  113.  * will cause the error text to be saved in the request_rec->notes 
  114.  * table, keyed to the string "error-notes", iff:
  115.  * - the severity level of the message is APLOG_WARNING or greater
  116.  * - there are no other "error-notes" set in request_rec->notes
  117.  * Once error-notes is set, it is up to the content handler to
  118.  * determine whether this text should be send back to the client.
  119.  * Note: Client generated text streams sent back to the  client MUST 
  120.  * be escaped to prevent CSS attacks.
  121.  */
  122. #define APLOG_TOCLIENT          (APLOG_LEVELMASK + 2)
  123.  
  124. /* normal but significant condition on startup, usually printed to stderr */
  125. #define APLOG_STARTUP           ((APLOG_LEVELMASK + 1) * 4) 
  126.  
  127. #ifndef DEFAULT_LOGLEVEL
  128. #define DEFAULT_LOGLEVEL    APLOG_WARNING
  129. #endif
  130.  
  131. extern int AP_DECLARE_DATA ap_default_loglevel;
  132.  
  133. #define APLOG_MARK    __FILE__,__LINE__
  134.  
  135. /**
  136.  * Set up for logging to stderr.
  137.  * @param p The pool to allocate out of
  138.  */
  139. AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
  140.  
  141. /**
  142.  * Replace logging to stderr with logging to the given file.
  143.  * @param p The pool to allocate out of
  144.  * @param file Name of the file to log stderr output
  145.  */
  146. AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 
  147.                                                const char *file);
  148.  
  149. /**
  150.  * Open the error log and replace stderr with it.
  151.  * @param s_main The main server
  152.  * @param p The pool to allocate out of
  153.  */
  154. void ap_open_logs (server_rec *s_main, apr_pool_t *p);
  155.  
  156. /* 
  157.  * The three primary logging functions, ap_log_error, ap_log_rerror, and 
  158.  * ap_log_perror use a printf style format string to build the log message.  
  159.  * It is VERY IMPORTANT that you not include any raw data from the network, 
  160.  * such as the request-URI or request header fields, within the format 
  161.  * string.  Doing so makes the server vulnerable to a denial-of-service 
  162.  * attack and other messy behavior.  Instead, use a simple format string 
  163.  * like "%s", followed by the string containing the untrusted data.
  164.  */
  165.  
  166. /**
  167.  * One of the primary logging routines in Apache.  This uses a printf-like
  168.  * format to log messages to the error_log.
  169.  * @param file The file in which this function is called
  170.  * @param line The line number on which this function is called
  171.  * @param level The level of this error message
  172.  * @param status The status code from the previous command
  173.  * @param s The server on which we are logging
  174.  * @param fmt The format string
  175.  * @param ... The arguments to use to fill out fmt.
  176.  * @tip Use APLOG_MARK to fill out file and line
  177.  * @warning It is VERY IMPORTANT that you not include any raw data from 
  178.  * the network, such as the request-URI or request header fields, within 
  179.  * the format string.  Doing so makes the server vulnerable to a 
  180.  * denial-of-service attack and other messy behavior.  Instead, use a 
  181.  * simple format string like "%s", followed by the string containing the 
  182.  * untrusted data.
  183.  * @deffunc void ap_log_error(const char *file, int line, int level, apr_status_t status, const server_rec *s, const char *fmt, ...) 
  184.  */
  185. AP_DECLARE(void) ap_log_error(const char *file, int line, int level, 
  186.                              apr_status_t status, const server_rec *s, 
  187.                              const char *fmt, ...)
  188.                 __attribute__((format(printf,6,7)));
  189.  
  190. /**
  191.  * The second of the primary logging routines in Apache.  This uses 
  192.  * a printf-like format to log messages to the error_log.
  193.  * @param file The file in which this function is called
  194.  * @param line The line number on which this function is called
  195.  * @param level The level of this error message
  196.  * @param status The status code from the previous command
  197.  * @param p The pool which we are logging for
  198.  * @param fmt The format string
  199.  * @param ... The arguments to use to fill out fmt.
  200.  * @tip Use APLOG_MARK to fill out file and line
  201.  * @warning It is VERY IMPORTANT that you not include any raw data from 
  202.  * the network, such as the request-URI or request header fields, within 
  203.  * the format string.  Doing so makes the server vulnerable to a 
  204.  * denial-of-service attack and other messy behavior.  Instead, use a 
  205.  * simple format string like "%s", followed by the string containing the 
  206.  * untrusted data.
  207.  * @deffunc void ap_log_perror(const char *file, int line, int level, apr_status_t status, apr_pool_t *p, const char *fmt, ...) 
  208.  */
  209. AP_DECLARE(void) ap_log_perror(const char *file, int line, int level, 
  210.                              apr_status_t status, apr_pool_t *p, 
  211.                              const char *fmt, ...)
  212.                 __attribute__((format(printf,6,7)));
  213.  
  214. /**
  215.  * The last of the primary logging routines in Apache.  This uses 
  216.  * a printf-like format to log messages to the error_log.
  217.  * @param file The file in which this function is called
  218.  * @param line The line number on which this function is called
  219.  * @param level The level of this error message
  220.  * @param status The status code from the previous command
  221.  * @param s The request which we are logging for
  222.  * @param fmt The format string
  223.  * @param ... The arguments to use to fill out fmt.
  224.  * @tip Use APLOG_MARK to fill out file and line
  225.  * @warning It is VERY IMPORTANT that you not include any raw data from 
  226.  * the network, such as the request-URI or request header fields, within 
  227.  * the format string.  Doing so makes the server vulnerable to a 
  228.  * denial-of-service attack and other messy behavior.  Instead, use a 
  229.  * simple format string like "%s", followed by the string containing the 
  230.  * untrusted data.
  231.  * @deffunc void ap_log_rerror(const char *file, int line, int level, apr_status_t status, request_rec *r, const char *fmt, ...) 
  232.  */
  233. AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level, 
  234.                                apr_status_t status, const request_rec *r, 
  235.                                const char *fmt, ...)
  236.                 __attribute__((format(printf,6,7)));
  237.  
  238. /**
  239.  * Convert stderr to the error log
  240.  * @param s The current server
  241.  * @deffunc void ap_error_log2stderr(server_rec *s)
  242.  */
  243. AP_DECLARE(void) ap_error_log2stderr(server_rec *s);
  244.  
  245. /**
  246.  * Log the current pid of the parent process
  247.  * @param p The pool to use for logging
  248.  * @param fname The name of the file to log to
  249.  */
  250. AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
  251.  
  252. /**
  253.  * Retrieve the pid from a pidfile.
  254.  * @param p The pool to use for logging
  255.  * @param filename The name of the file containing the pid
  256.  * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
  257.  */
  258. AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename, pid_t *mypid);
  259.  
  260. typedef struct piped_log piped_log;
  261.  
  262. /**
  263.  * The piped logging structure.  Piped logs are used to move functionality
  264.  * out of the main server.  For example, log rotation is done with piped logs.
  265.  */
  266. struct piped_log {
  267.     /** The pool to use for the piped log */
  268.     apr_pool_t *p;
  269.     /** The pipe between the server and the logging process */
  270.     apr_file_t *fds[2];
  271.     /* XXX - an #ifdef that needs to be eliminated from public view. Shouldn't
  272.      * be hard */
  273. #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
  274.     /** The name of the program the logging process is running */
  275.     char *program;
  276.     /** The pid of the logging process */
  277.     apr_proc_t *pid;
  278. #endif
  279. };
  280.  
  281. /**
  282.  * Open the piped log process
  283.  * @param p The pool to allocate out of
  284.  * @param program The program to run in the logging process
  285.  * @return The piped log structure
  286.  * @deffunc piped_log *ap_open_piped_log(apr_pool_t *p, const char *program)
  287.  */
  288. AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program);
  289.  
  290. /**
  291.  * Close the piped log and kill the logging process
  292.  * @param pl The piped log structure
  293.  * @deffunc void ap_close_piped_log(piped_log *pl)
  294.  */
  295. AP_DECLARE(void) ap_close_piped_log(piped_log *pl);
  296.  
  297. /**
  298.  * A macro to access the read side of the piped log pipe
  299.  * @param pl The piped log structure
  300.  * @return The native file descriptor
  301.  * @deffunc ap_piped_log_read_fd(pl)
  302.  */
  303. #define ap_piped_log_read_fd(pl)    ((pl)->fds[0])
  304.  
  305. /**
  306.  * A macro to access the write side of the piped log pipe
  307.  * @param pl The piped log structure
  308.  * @return The native file descriptor
  309.  * @deffunc ap_piped_log_read_fd(pl)
  310.  */
  311. #define ap_piped_log_write_fd(pl)    ((pl)->fds[1])
  312.  
  313. AP_DECLARE_HOOK(void, error_log, (const char *file, int line, int level,
  314.                        apr_status_t status, const server_rec *s,
  315.                        const request_rec *r, apr_pool_t *pool,
  316.                        const char *errstr))
  317.  
  318. #ifdef __cplusplus
  319. }
  320. #endif
  321.  
  322. #endif    /* !APACHE_HTTP_LOG_H */
  323.